package com.xoa.controller.nccloud;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xoa.model.nccloud.*;
import com.xoa.service.nccloud.*;
import com.xoa.util.DateFormat;
import com.xoa.util.common.wrapper.BaseWrapper;
import org.apache.commons.collections4.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * NCC 基础数据同步类
 */
@Controller
@RequestMapping(value = "/nccloud/api/sync")
public class SyncNCCDataController {

    @Autowired
    private INCCloudService nccloudService;

    @Autowired
    INCCInterFaceLogService logService;

    @Autowired
    INCCPsndocService psndocService;
    @Autowired
    NccHrorgService nccHrorgService;
    @Autowired
    NccHrdeptService nccHrdeptService;
    @Autowired
    NccPostVService nccPostVService;
    //NCC 视图操作类
    @Autowired
    INCCViewService viewService;

    @Autowired
    NccPostseriesVService nccPostseriesVService;

    private static SimpleDateFormat sdf1 = new SimpleDateFormat(
            "yyyy-MM-dd");

    /*
     * 获取照证件照
     * */
    @RequestMapping("/identification_photo")
    @ResponseBody
    public BaseWrapper getIdentificationPhoto(String pkSndoc) throws Exception {
        BaseWrapper baseWrapper = new BaseWrapper();
        try {

            String requstBody = "{\"pk_psndoc\":\"" + pkSndoc + "\"}";
            String orgResult = nccloudService.sendApi(nccloudService.IdentificationPhoto, requstBody);
            JSONObject jsonObject = JSON.parseObject(orgResult);

            StringBuilder stringBuilder = null;
            //是否成功
            if (JSON.parseObject(orgResult).getIntValue("code") == 1) {
                if (null != jsonObject.getString("data") && !jsonObject.getString("data").equals("")) {

                    stringBuilder = new StringBuilder(jsonObject.getJSONObject("data").getString(pkSndoc));


                } else {
                    throw new RuntimeException("请求NC视图data-null");
                }
            } else {
                throw new RuntimeException(jsonObject.getString("message"));
            }

            //=====3、成功
            baseWrapper.setFlag(true);
            baseWrapper.setMsg("根据人员pk查询证件照成功");
            baseWrapper.setStatus(true);
            baseWrapper.setData(stringBuilder.toString());
            //接口调用日志保存
            NCCInterfaceLog ncclog = new NCCInterfaceLog();
            ncclog.setBusinessNo("");
            ncclog.setContent(requstBody);
            ncclog.setName("根据人员pk查询证件照成功");
            ncclog.setResultLong(orgResult);
            ncclog.setState("1");
            ncclog.setDisposeState("0");
            logService.save(ncclog);

        } catch (Exception e) {
            //=====、失败
            baseWrapper.setFlag(false);
            baseWrapper.setMsg("根据人员pk查询证件照失败|message:" + e.getMessage());
            baseWrapper.setStatus(true);

            //接口调用日志保存
            NCCInterfaceLog ncclog = new NCCInterfaceLog();
            ncclog.setBusinessNo("");
            ncclog.setContent("");
            ncclog.setName("根据人员pk查询证件照失败");
            ncclog.setResultLong(e.getMessage());
            ncclog.setState("0");
            ncclog.setDisposeState("0");
            logService.save(ncclog);
        }
        return baseWrapper;

    }

    /*
     * 按工号查询人员示例
     * */
    @RequestMapping("querypsn")
    @ResponseBody
    public BaseWrapper querypsn(String code) throws Exception {

        BaseWrapper baseWrapper = new BaseWrapper();
        if (StringUtils.isBlank(code)) {
            baseWrapper.setFlag(false);
            baseWrapper.setMsg("人员编号不能为空");
            return baseWrapper;
        }
        NccPsninfo nccPsninfo = new NccPsninfo();
        nccPsninfo.setCode(code);
        List<NccPsninfo> psninfoList = psndocService.selectPsn(nccPsninfo);
        if (psninfoList.size() > 0) {
            nccPsninfo = psninfoList.get(0);
        }
        baseWrapper.setFlag(true);
        baseWrapper.setMsg("成功");
        baseWrapper.setStatus(true);
        baseWrapper.setData(nccPsninfo);
        return baseWrapper;
    }

    /**
     * 将查询出的组织及联动部门一起插入数据库
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("queryhrorg")
    @ResponseBody
    public BaseWrapper djdz(HttpServletRequest request) throws Exception {
        BaseWrapper baseWrapper = new BaseWrapper();
        try {
            //=====1、查询组织
            String orfRequstBody = "{\"orgtype\":\"hr\"}";
            String orgResult = nccloudService.sendApi(nccloudService.queryOrgUrl, orfRequstBody);
            JSONObject resultJson = JSON.parseObject(orgResult);
            if (resultJson.getIntValue("code") == 1) {
                if (null != resultJson.getJSONArray("data").toJSONString() && !resultJson.getJSONArray("data").toJSONString().equals("[]")) {
                    JSONArray orgResultJsonArray = JSON.parseObject(orgResult).getJSONArray("data");
                    this.nccLog(orfRequstBody, "查询组织", orgResult);

                    //清空表
                    viewService.truncateTable("ncc_hrorg");
                    viewService.truncateTable("ncc_hrdept");
                    //=====2、遍历组织json数组做相应操作
                    for (int i = 0; i < orgResultJsonArray.size(); i++) {
                        NccHrorg nccHrorg = JSON.toJavaObject(orgResultJsonArray.getJSONObject(i), NccHrorg.class);


                        //=====3、根据组织查询部门
                        String deptRequstBody = "{ \"pk_org\": \"" + nccHrorg.getPkOrg() + "\" }";
                        String deptResult = nccloudService.sendApi(nccloudService.queryDeptUrl, deptRequstBody);
                        if (deptResult.equals("\"没有符合条件的数据\"")) {
                            this.nccLog(deptRequstBody, "根据组织查询部门没有符合条件的数据", deptResult);
                            continue;
                        }
                        this.nccLog(deptRequstBody, "根据组织查询部门", deptResult);
                        JSONArray deptResultJsonArray = JSON.parseArray(deptResult);


                        //=====4、遍历部门json数组做相应操作

                        //部门和组织都查出来进行添加操作
                        nccHrorgService.itriptxAddNccHrorg(nccHrorg);
                        for (int b = 0; b < deptResultJsonArray.size(); b++) {
                            NccHrdept nccHrdept = JSON.toJavaObject(deptResultJsonArray.getJSONObject(b), NccHrdept.class);
                            nccHrdeptService.itriptxAddNccHrdept(nccHrdept);
                        }
                    }
                } else {
                    throw new RuntimeException("请求组织信息data-null");
                }
            } else {
                throw new RuntimeException(resultJson.getString("message"));
            }
            //=====5、成功
            baseWrapper.setFlag(true);
            baseWrapper.setMsg("成功");
            baseWrapper.setStatus(true);
            this.nccLog("", "插入组织或部门成功", JSON.toJSONString(baseWrapper));

        } catch (Exception e) {
            //=====、失败
            baseWrapper.setFlag(false);
            baseWrapper.setMsg(e.getMessage());
            baseWrapper.setStatus(true);
            this.nccLog("", "插入组织或部门错误", JSON.toJSONString(baseWrapper));
            System.out.println("错误" + e.getMessage());
        }
        return baseWrapper;
    }

    /**
     * 根据组织查询相关部门
     *
     * @param orgName
     * @return
     * @throws Exception
     */
    @RequestMapping("queryhrdeptBypk_org")
    @ResponseBody
    public BaseWrapper queryhrdeptBypk_org(String orgName) throws Exception {
        BaseWrapper baseWrapper = new BaseWrapper();
        try {

            //====1、根据组织orgName查询出组织
            //设置参数
            Map<String, Object> mapParam = new HashedMap<>();
            mapParam.put("name", orgName);

            //获取组织集合
            List<NccHrorg> nccHrorgListByMap = nccHrorgService.getNccHrorgListByMap(mapParam);
            if (null != nccHrorgListByMap && nccHrorgListByMap.size() != 0) {


                //====2、根据组织pk查出部门
                //设置参数
                mapParam = new HashedMap<>();
                mapParam.put("pkOrg", nccHrorgListByMap.get(0).getPkOrg());

                //获取部门集合
                List<NccHrdept> nccHrdeptListByMap = nccHrdeptService.getNccHrdeptListByMap(mapParam);
                if (null != nccHrdeptListByMap && nccHrdeptListByMap.size() != 0) {
                    baseWrapper.setFlag(true);
                    baseWrapper.setMsg("成功");
                    baseWrapper.setStatus(true);
                    baseWrapper.setData(nccHrdeptListByMap);
                } else {
                    throw new RuntimeException("没有pk_org:" + mapParam.get("pk_org") + "相关部门数据");
                }

            } else {
                throw new RuntimeException("没有相关组织数据");

            }

        } catch (Exception e) {
            //错误
            baseWrapper.setFlag(false);
            baseWrapper.setMsg(e.getMessage());
            baseWrapper.setStatus(true);
            this.nccLog("", "据组织查询相关部门", JSON.toJSONString(baseWrapper));
            System.out.println("错误" + e.getMessage());
        }
        return baseWrapper;
    }

    /**
     * 根据部门查询相关岗位
     *
     * @param orgName
     * @return
     * @throws Exception
     */
    @RequestMapping("querypostBypk_orgAndpk_dept")
    @ResponseBody
    public BaseWrapper querypostBypk_orgAndpk_dept(String orgName, String deptName) throws Exception {
        BaseWrapper baseWrapper = new BaseWrapper();
        try {
            //====1、根据组织名称查询组织pk
            //设置参数
            Map<String, Object> mapParam = new HashedMap<>();
            mapParam.put("name", orgName);
            List<NccHrorg> nccHrorgListByMap = nccHrorgService.getNccHrorgListByMap(mapParam);
            if (null != nccHrorgListByMap && nccHrorgListByMap.size() != 0) {
                //====2、根据组织pk和部门名称查出部门pk
                //设置参数
                mapParam = new HashedMap<>();
                mapParam.put("pkOrg", nccHrorgListByMap.get(0).getPkOrg());
                mapParam.put("name", deptName);
                //获取部门集合
                List<NccHrdept> nccHrdeptListByMap = nccHrdeptService.getNccHrdeptListByMap(mapParam);
                if (null != nccHrdeptListByMap && nccHrdeptListByMap.size() != 0) {
                    //====3、根据部门pk查出岗位列表
                    //设置参数
                    mapParam = new HashedMap<>();
                    mapParam.put("pkDept", nccHrdeptListByMap.get(0).getPkDept());
                    //获取岗位列表
                    List<NccPostV> nccHrPostListByMap = nccPostVService.getNccPostVListByMap(mapParam);
                    if (null != nccHrPostListByMap && nccHrPostListByMap.size() != 0) {
                        baseWrapper.setFlag(true);
                        baseWrapper.setMsg("成功");
                        baseWrapper.setStatus(true);
                        baseWrapper.setData(nccHrPostListByMap);
                    } else {
                        throw new RuntimeException("没有pk_dept:" + mapParam.get("pk_dept") + "相关岗位数据");
                    }
                } else {
                    throw new RuntimeException("没有相关部门数据");
                }
            } else {
                throw new RuntimeException("没有相关组织数据");
            }

        } catch (Exception e) {
            //错误
            baseWrapper.setFlag(false);
            baseWrapper.setMsg(e.getMessage());
            baseWrapper.setStatus(true);
            this.nccLog("", "据部门pk查询相关岗位", JSON.toJSONString(baseWrapper));
            System.out.println("错误" + e.getMessage());
        }
        return baseWrapper;
    }

    /*
     * 根据业务单元主键查询部门
     * */
    @RequestMapping("queryhrdept")
    @ResponseBody
    public BaseWrapper queryhrdept(String pkorg) throws Exception {
        String requstBody = "{ \"pk_org\": \"" + pkorg + "\" }";
        String result = nccloudService.sendApi(nccloudService.queryDeptUrl, requstBody);
        // 接口调用日志保存
        NCCInterfaceLog ncclog = new NCCInterfaceLog();
        ncclog.setBusinessNo("hrorg");
        ncclog.setContent(requstBody);
        ncclog.setName("查询HR部门");
        ncclog.setResultLong(result);
        ncclog.setState("1");
        ncclog.setDisposeState("0");
        logService.save(ncclog);

        BaseWrapper baseWrapper = new BaseWrapper();
        baseWrapper.setFlag(true);
        baseWrapper.setMsg("成功");
        baseWrapper.setStatus(true);
        baseWrapper.setData(result);
        return baseWrapper;
    }

//    /**
//     *
//     * 查询工资条
//     * @param cyear 查询年份
//     * @param cperiod 查询月份
//     * @param pk_psndoc 人员主键
//     * @return
//     * @throws Exception
//     */
//    @RequestMapping("queryWagesTip")
//    @ResponseBody
//    public BaseWrapper queryWagesTip(String cyear,String cperiod,String pk_psndoc) throws Exception {
//        BaseWrapper baseWrapper = new BaseWrapper();
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("cyear", cyear);
//        jsonObject.put("cperiod",cperiod);
//        jsonObject.put("pk_psndoc",pk_psndoc);
//        String requstBody = jsonObject.toJSONString();
//        String result = nccloudService.sendApi(nccloudService.queryWagesTipUrl, requstBody);
//        JSONObject resultJson = JSONObject.parseObject(result);
//        if (resultJson.getIntValue("code") == 1 && null != resultJson.getJSONArray("data").toJSONString() && !resultJson.getJSONArray("data").toJSONString().equals("[]")){
//            StringBuilder stringBuilder = new StringBuilder();
//            baseWrapper.setFlag(true);
//            baseWrapper.setMsg("查询工资条成功");
//            baseWrapper.setStatus(true);
//            baseWrapper.setData(stringBuilder.toString());
//
//            // 接口调用日志保存
//            NCCInterfaceLog ncclog = new NCCInterfaceLog();
//            ncclog.setBusinessNo("wagesTip");
//            ncclog.setContent(requstBody);
//            ncclog.setName("查询工资条");
//            ncclog.setResultLong(result);
//            ncclog.setState("1");
//            ncclog.setDisposeState("0");
//            logService.save(ncclog);
//
//        }else{
//            StringBuilder stringBuilder = new StringBuilder();
//            baseWrapper.setFlag(true);
//            baseWrapper.setMsg("根据工资条接口失败");
//            baseWrapper.setStatus(true);
//            baseWrapper.setData(stringBuilder.toString());
//
//            // 接口调用日志保存
//            NCCInterfaceLog ncclog = new NCCInterfaceLog();
//            ncclog.setBusinessNo("wagesTip");
//            ncclog.setContent(requstBody);
//            ncclog.setName("查询工资条失败");
//            ncclog.setResultLong(result);
//            ncclog.setState("0");
//            ncclog.setDisposeState("0");
//            logService.save(ncclog);
//        }
//        return baseWrapper;
//    }

    /*
     * HR人员同步
     * */

    @RequestMapping("querypsndoc")
    @ResponseBody
    public BaseWrapper querypsndoc(String pkorg, String pkdept) throws Exception {


        BaseWrapper baseWrapper = new BaseWrapper();
        int add = 0, modify = 0, del = 0;
        try {

            //请求获取人员全部信息
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("pk_group", "0");
            /*jsonObject.put("pk_org","");
            jsonObject.put("pk_dept","");
            jsonObject.put("code","");
            jsonObject.put("name","");
            jsonObject.put("pk_psndoc","");
            jsonObject.put("id","");
            jsonObject.put("indocflag","");
            jsonObject.put("ts_begin","");
            jsonObject.put("ts_end","");*/
            String requstBody = jsonObject.toJSONString();

            String result = nccloudService.sendApi(nccloudService.queryPsndoctUrl, requstBody);
            JSONObject resultJson = JSONObject.parseObject(result);


            //判断是返回值否正确
            if (resultJson.getIntValue("code") == 1 && null != resultJson.getJSONArray("data").toJSONString() && !resultJson.getJSONArray("data").toJSONString().equals("[]")) {

                //清空表
                viewService.truncateTable("ncc_psninfo");


                //解析人员信息提取数据
                JSONArray dataArray = resultJson.getJSONArray("data");
                a:
                for (int i = 0; i < dataArray.size(); i++) {


                    NccPsninfo nccPsninfo = new NccPsninfo();
                    JSONObject psndoc = dataArray.getJSONObject(i);
                    JSONObject psninfo = psndoc.getJSONObject("psninfo"); //人员基本信息
                    JSONArray jobArray = psndoc.getJSONArray("psninfo_job"); //基本工作信息
                    JSONArray jobArray_hipsninfo_job = psndoc.getJSONArray("hipsninfo_job");//人力基本工作信息


                    /**
                     * 人力工作记录
                     */
                    if (null != jobArray_hipsninfo_job) {
                        //遍历人力基本工作信息判断职位是否为主职，是否在岗、记录是否最新
                        for (int a = 0; a < jobArray_hipsninfo_job.size(); a++) {

                            //判断人力工作记录是否最新
                            if (null != jobArray_hipsninfo_job.getJSONObject(a).getString("lastflag") && jobArray_hipsninfo_job.getJSONObject(a).getString("lastflag").equals("Y")) {


                                //判断取值是否为空则跳过
                                String ismainjob = null;
                                String poststat = null;
                                try {
                                    ismainjob = jobArray_hipsninfo_job.getJSONObject(a).getString("ismainjob");
                                    poststat = jobArray_hipsninfo_job.getJSONObject(a).getString("poststat");
                                    if (null == ismainjob || null == poststat) {
                                        throw new Exception();
                                    }
                                } catch (Exception e) {
                                    continue;
                                }

                                if (ismainjob.equals("Y") && poststat.equals("Y")) {


                                    JSONObject jobArray_hipsninfo_jobJSONObject = jobArray_hipsninfo_job.getJSONObject(a);
                                    nccPsninfo.setJobglbdef2(jobArray_hipsninfo_jobJSONObject.getString("jobglbdef2"));//任现职时间
                                    nccPsninfo.setJobglbdef4(jobArray_hipsninfo_jobJSONObject.getString("jobglbdef4"));//任现职级时间

                                    if (jobArray_hipsninfo_jobJSONObject.containsKey("pk_post")) {
                                        nccPsninfo.setPkPost(jobArray_hipsninfo_jobJSONObject.getJSONObject("pk_post").getString("pk"));//岗位主键
                                    }

                                    if (jobArray_hipsninfo_jobJSONObject.containsKey("pk_postseries")) {
                                        nccPsninfo.setPkPostseries(jobArray_hipsninfo_jobJSONObject.getJSONObject("pk_postseries").getString("pk"));//岗位序列主键
                                    }

                                    if (jobArray_hipsninfo_jobJSONObject.containsKey("jobglbdef3")) {
                                        nccPsninfo.setJobglbdef3Name(jobArray_hipsninfo_jobJSONObject.getJSONObject("jobglbdef3").getString("name"));//行政级别名称
                                        nccPsninfo.setJobglbdef3(jobArray_hipsninfo_jobJSONObject.getJSONObject("jobglbdef3").getString("pk"));//行政级别pk
                                    }

                                    /**
                                     * 人员信息
                                     */
                                    if (null != psninfo) {
                                        /**
                                         * 人员对象
                                         */
                                        nccPsninfo.setCode(psninfo.getString("code").trim());
                                        nccPsninfo.setName(psninfo.getString("name"));
                                        nccPsninfo.setCreationtime(psninfo.getString("creationtime"));
                                        nccPsninfo.setDr(psninfo.getInteger("dr"));
                                        nccPsninfo.setEnablestate(psninfo.getInteger("enablestate"));
                                        nccPsninfo.setBirthdate(psninfo.getString("birthdate"));
                                        nccPsninfo.setSex(psninfo.getInteger("sex"));
                                        nccPsninfo.setMobile(psninfo.getString("mobile"));
                                        nccPsninfo.setPkPsndoc(psninfo.getString("pk_psndoc"));
                                        nccPsninfo.setPkGroup(psninfo.getJSONObject("pk_group").getString("pk"));
                                        nccPsninfo.setPkGroupCode(psninfo.getJSONObject("pk_group").getString("code"));
                                        try {
                                            nccPsninfo.setJoinworkdate(psninfo.getString("joinworkdate"));
                                        } catch (Exception e) {
                                            nccPsninfo.setJoinworkdate(null);
                                        }
                                        //设置组织
                                        nccPsninfo.setPkOrg(psninfo.getJSONObject("pk_org").getString("pk"));
                                        nccPsninfo.setPkOrgCode(psninfo.getJSONObject("pk_org").getString("code"));
                                        nccPsninfo.setPkOrgName(psninfo.getJSONObject("pk_org").getString("name"));

                                    } else {
                                        continue a;
                                    }

                                    /**
                                     * 基础工作记录
                                     */
                                    if (null != jobArray) {
                                        //取最新的入职日期
                                        Map<Long, Integer> map = new HashMap<>();
                                        //遍历人员基本工作信息
                                        for (int b = 0; b < jobArray.size(); b++) {
                                            JSONObject job = jobArray.getJSONObject(b);
                                            map.put(sdf1.parse(job.getString("indutydate")).getTime(), b);

                                        }


                                        Set<Map.Entry<Long, Integer>> entries = map.entrySet();
                                        List<Map.Entry<Long, Integer>> entryArrayList = new ArrayList<>(entries);
                                        //判断是否只有一条信息
                                        if (entryArrayList.size() > 1) {

                                            Collections.sort(entryArrayList, new Comparator<Map.Entry<Long, Integer>>() {
                                                @Override
                                                public int compare(Map.Entry<Long, Integer> o1, Map.Entry<Long, Integer> o2) {
                                                    return (int) (o2.getKey() - o1.getKey());
                                                }
                                            });
                                        }

                                        JSONObject job = jobArray.getJSONObject(entryArrayList.get(0).getValue());
                                        //设置职位类型
                                        nccPsninfo.setPkPsncl(job.getJSONObject("pk_psncl").getString("pk"));
                                        nccPsninfo.setPkPsnclCode(job.getJSONObject("pk_psncl").getString("code"));
                                        nccPsninfo.setPkPsnclName(job.getJSONObject("pk_psncl").getString("name"));
                                        //设置人员任职时间
                                        nccPsninfo.setIndutydate(job.getString("indutydate"));
                                        nccPsninfo.setEnddutydate(job.getString("enddutydate"));

                                        //设置部门
                                        nccPsninfo.setPkDept(job.getJSONObject("pk_dept").getString("pk"));
                                        nccPsninfo.setPkDeptCode(job.getJSONObject("pk_dept").getString("code"));
                                        nccPsninfo.setPkDeptName(job.getJSONObject("pk_dept").getString("name"));

                                        if (job.containsKey("pk_job")) {
                                            nccPsninfo.setPkJob(job.getJSONObject("pk_job").getString("pk"));//职务pk
                                            nccPsninfo.setPkJobName(job.getJSONObject("pk_job").getString("name"));//职务名称
                                        }
                                    }

                                    add++;
                                    psndocService.savePsn(nccPsninfo);

                                    break;
                                }
                            }
                        }
                    }
                }
            } else {
                throw new RuntimeException("data-null");
            }

           /* if(result.length()<100000){
                // 接口调用日志保存
                NCCInterfaceLog ncclog = new NCCInterfaceLog();
                ncclog.setBusinessNo("hrorg");
                ncclog.setContent(requstBody);
                ncclog.setName("HR人员同步"+"新增人员：" + add + ";修改人员：" + modify);
                ncclog.setResultLong(result);
                ncclog.setState("1");
                ncclog.setDisposeState("0");
                logService.save(ncclog);
            }*/
            // 接口调用日志保存
            NCCInterfaceLog ncclog = new NCCInterfaceLog();
            ncclog.setBusinessNo("ncc_psninfo");
            ncclog.setContent(requstBody);
            ncclog.setName("HR人员视图同步" + "新增人员：" + add + ";修改人员：" + modify + ";删除人员：" + del);
            ncclog.setResultLong("");
            ncclog.setState("1");
            ncclog.setDisposeState("0");
            logService.save(ncclog);

            baseWrapper.setFlag(true);
            baseWrapper.setMsg("HR人员视图同步" + "新增人员：" + add + ";修改人员：" + modify + ";删除人员：" + del);
            baseWrapper.setStatus(true);

        } catch (Exception e) {
            baseWrapper.setFlag(false);
            baseWrapper.setMsg("HR人员视图同步失败" + e.getMessage() + add);
            baseWrapper.setStatus(true);
            // 接口调用日志保存
            NCCInterfaceLog ncclog = new NCCInterfaceLog();
            ncclog.setBusinessNo("hrorg");
            ncclog.setContent("");
            ncclog.setName("HR人员视图同步失败");
            ncclog.setResultLong(e.getMessage());
            ncclog.setState("0");
            ncclog.setDisposeState("0");
            logService.save(ncclog);
        }
        return baseWrapper;
    }

    /**
     * 日志添加
     *
     * @param requstBody
     * @param name
     * @param result
     * @throws Exception
     */
    public void nccLog(String requstBody, String name, String result) throws Exception {
        //接口调用日志保存
        NCCInterfaceLog ncclog = new NCCInterfaceLog();
        ncclog.setBusinessNo("hrorg");
        ncclog.setContent(requstBody);
        ncclog.setName(name);
        ncclog.setResultLong(result);
        ncclog.setState("1");
        ncclog.setDisposeState("0");
        logService.save(ncclog);
    }


}
